﻿//加载分页条
function LoadPageBar(callURL, Pagination, currentPage, container) {
    ajaxGet(callURL + "?" + container.find("#formSearch").serialize(), null, function (html) {
        container.find("#loanTable").html(html).attr("serach", "isSearch");
        var rows = container.find("#loanTable #hidden_rows").val();
        var pageSize = container.find("#loanTable #hidden_pageSize").val();
        var pageCount = container.find("#loanTable #hidden_pageCount").val();
        var pageIndex = container.find("#loanTable #hidden_pageIndex").val();
        container.find("#pageSetting").html("每页" + pageSize + "条记录，共有" + pageCount + "页，共有" + rows + "条记录");
        //分页，PageCount是总条目数，这是必选参数，其它参数都是可选
        container.find("#" + Pagination).pagination(rows, {
            // callback: PageCallback,
            prev_text: '上一页',       //上一页按钮里text
            next_text: '下一页',       //下一页按钮里text
            items_per_page: pageSize,  //显示条数
            num_display_entries: 5,    //连续分页主体部分分页条目数
            current_page: currentPage,   //当前页索引
            num_edge_entries: 5,      //两侧首尾分页条目数
            callURL: callURL,
            callback: function (index) {
                WriteGoBar(callURL, container);
                if (container.find("#loanTable").attr("serach") == "isSearch") {
                    container.find("#loanTable").removeAttr("serach");
                    return;//没有点击分页条
                }
                index++;
                container.find("#pageIndex").val(index);
                InitTable(callURL, container);
            }
        });
    });
    //$.get(callURL, container.find("#formSearch").serialize(), function (html) {
      
    //});

}
//请求数据
function InitTable(callURL, container) {
    $.get(callURL, container.find("#formSearch").serialize(), function (html, status) {
        container.find("#loanTable").html(html);

    });
}
//追加跳转功能
function WriteGoBar(callURL, container) {
    container.find("#Pagination").children("#gopage,#goskip").remove();
    container.find("#Pagination>div").append("<input type='text' id='gopage'/><a id='goskip'>跳转</a>");
    container.find("#goskip").click(function () {
        var page = container.find("#gopage").val();
        if (!/^[1-9]([0-9])*$/.test(page)) {
            alert("请输入数字或者正数!");
            container.find("#gopage").val("");
            return false;
        }
        if (page == "") {
            alert("请输入数字!");
            container.find("#gopage").val("");
            return false;
        }
        container.find("#pageIndex").val(page);
        container.find("#loanTable").attr("serach", "isSearch");
        LoadPageBar(callURL, "Pagination", page - 1, container);

    });
}
